package com.example.tellwin.home.adpater;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tellwin.R;
import com.example.tellwin.home.bean.VoteBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : LinZePeng
 * @date : 2020/11/11
 * @Describe ：
 **/
public class VoteAdapter extends RecyclerView.Adapter<VoteAdapter.VoteViewHolder> {

    private List<VoteBean> voteBeanList = new ArrayList<>();
    Context context;

    public void setVoteBeanList(List<VoteBean> voteBeanList) {
        this.voteBeanList = voteBeanList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public VoteViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        context = parent.getContext();
        return new VoteViewHolder(LayoutInflater.from(context).inflate(R.layout.item_vote, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull VoteViewHolder holder, int position) {
        VoteBean voteBean = voteBeanList.get(position);
        holder.voteNameTv.setText(voteBean.getName());
        holder.rankingTv.setText(voteBean.getRanking()+"");
        holder.integralTv.setText(voteBean.getIntegral()+"");
    }

    @Override
    public int getItemCount() {
        return voteBeanList.size();
    }


    class VoteViewHolder extends RecyclerView.ViewHolder {
        TextView voteNameTv;
        TextView rankingText;
        TextView rankingTv;
        TextView getIntegralText;
        TextView integralTv;

        public VoteViewHolder(@NonNull View itemView) {
            super(itemView);
            voteNameTv = (TextView) itemView.findViewById(R.id.vote_name_tv);
            rankingText = (TextView) itemView.findViewById(R.id.ranking_text);
            rankingTv = (TextView) itemView.findViewById(R.id.ranking_tv);
            getIntegralText = (TextView) itemView.findViewById(R.id.get_integral_text);
            integralTv = (TextView) itemView.findViewById(R.id.integral_tv);
        }
    }
}
